#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require


#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"


layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;

layout(location = 0) in vec3 inEyeDir[];
layout(location = 1) in vec3 inNormal[];
layout(location = 2) in vec4 inVert[];
layout(location = 3) in mat4 inCameraView[];
layout(location = 7) in uint inMaterialID[];
layout(location = 8) in uint inElementID[];
layout(location = 9) in uint outOffset_Face[];
layout(location = 10) in uint inAnimationType[];
layout(location = 11) in vec2 inUV[];
in gl_PerVertex {
	vec4 gl_Position;
}gl_in[];



layout(location = 0) out vec3 outEyeDir;
layout(location = 1) out vec3 outNormal;
layout(location = 2) out vec4 outVert;
layout(location = 3) out flat mat4 outCameraView;
layout(location = 7) out flat uint outMaterialID;
layout(location = 8) out float outElementID;
layout(location = 9) out vec2 outUV;

out gl_PerVertex {
	vec4 gl_Position;
};


layout(std430, set = 1, scalar, column_major, binding = DEF_BINDING_MeshFaceID) readonly buffer Buf0 {
	S_FaceElement m_Face[];
};



void main(void){

	//vec3 normal = normalize(f_surface_FaceNormal(gl_in[0].gl_Position.xyz, gl_in[1].gl_Position.xyz, gl_in[2].gl_Position.xyz));
	vec3 normal = normalize(f_surface_FaceNormal(inNormal[0], inNormal[1], inNormal[2]));
	//vec3 normal = normalize(gl_in[0].gl_Position.xyz + gl_in[1].gl_Position.xyz + gl_in[2].gl_Position.xyz);

	S_FaceElement face = m_Face[ outOffset_Face[0] + gl_PrimitiveIDIn];
	//float f = (4 / (face.FacesMooth + 1)) * 0.25;

	for(uint i=0; i<3; ++i){
		outEyeDir = inEyeDir[i];
		outNormal = normal;
		outVert = inVert[i];
		outCameraView = inCameraView[i];
		outMaterialID = inMaterialID[i];

		outElementID = face.FacesMooth;
		outUV = inUV[i];
		//outElementID = 0.5 * gl_PrimitiveIDIn;
		//outElementID = 1;
		//switch(inElementID[i]){
		//	case 0:{
		//		break;
		//	}
		//	case 1:{
		//		break;
		//	}
		//	case 2:{
		//		break;
		//	}
		//	case 3:{
		//		break;
		//	}
		//	case 4:{
		//		break;
		//	}
		//}

		gl_Position = gl_in[i].gl_Position;
		EmitVertex();
	}
	
	EndPrimitive();
}



